<template>
  <div class="employee-container">
    <!-- 搜索区域 -->
    <div class="search-container">
      <div class="search-label">企业名称：</div>
      <el-input v-model="params.enterpriseName" clearable placeholder="请输入内容" class="search-main" @input="check" />
      <el-form id="errorfrom" label-position="left" label-width="100px">
        <el-form-item label="租赁起止日期">
          <el-date-picker
            v-model="timeArr"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            @clear="resetTime"
          />
        </el-form-item>
      </el-form>
      <el-button type="primary" class="buttonn" @click="check">查询</el-button>
    </div>
    <div class="create-container">
      <el-button type="primary" @click="openDialog">添加账单</el-button>
    </div>
    <!-- 表格区域 -->
    <div class="table">
      <el-table style="width: 100%" :data="propertyList">
        <el-table-column type="index" label="序号" width="60" />
        <el-table-column label="账单编号" width="180" prop="billNumber" />
        <el-table-column label="企业名称" width="180" prop="enterpriseName" />
        <el-table-column label="租赁楼宇" width="120" prop="buildingName" />
        <el-table-column label="物业费(元/m²)" width="120" prop="propertyFeePrice" />
        <el-table-column label="账单金额(元)" width="120" prop="paymentAmount" />
        <el-table-column label="缴费时间" width="200" prop="createTime" />
        <el-table-column label="操作" width="120">
          <template #default="{row}">
            <el-button size="mini" type="text" @click="Viwe(row.id)">查看</el-button>
            <el-button size="mini" type="text" @click="delBill(row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      layout="total, prev, pager, next"
      :page-size="params.pageSize"
      :total="total"
      @current-change="pageChange"
    />
    <addDialog
      ref="addDialog"
      :dialog-show="dialogShow"
      @closeDialog="closeDialog"
    />
  </div>
</template>

<script>
import { getPropertyListAPI, delBillAPI } from '@/api/property'
import addDialog from './addemployee.vue'
export default {
  name: 'Property',
  components: {
    addDialog
  },
  data() {
    return {
      propertyList: [],
      params: {
        enterpriseName: '',
        page: 1,
        pageSize: 5
      },
      timeArr: [],
      total: null,
      dialogShow: false
    }
  },
  mounted() {
    this.getPropertyList()
  },
  methods: {
    async getPropertyList() {
      console.log({ start: this.timeArr[0], end: this.timeArr[1] })
      const res = await getPropertyListAPI({ ...this.params, start: this.timeArr[0], end: this.timeArr[1] })
      this.propertyList = res.data.rows
      this.total = res.data.total
    },
    check() {
      this.getPropertyList()
    },
    openDialog() {
      this.dialogShow = true
    },
    closeDialog() {
      this.dialogShow = false
    },
    pageChange(page) {
      this.params.page = page
      this.getPropertyList()
    },
    Viwe(id) {
      this.$refs.addDialog.checkDetail(id)
      this.dialogShow = true
    },
    async delBill(id) {
      await delBillAPI(id)
      this.getPropertyList()
    },
    resetTime() {
      this.getPropertyList()
    }
  }
}
</script>

<style lang="scss" scoped>
.employee-container {
  padding: 10px;
}

.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, .9);
  ;
  padding-bottom: 20px;

  .search-label {
    width: 100px;
  }

  .search-main {
    width: 220px;
    margin-right: 10px;
  }
  #errorfrom{
    margin-top: 20px;
  }
    .buttonn{
    margin-left: 15px;
  }
}
.create-container{
  margin: 10px 0px;
}
.page-container{
  padding:4px 0px;
  text-align: right;
}
.form-container{
  padding:0px 80px;
}
</style>
